package forceoffer;

import java.util.ArrayList;
import java.util.Stack;
import java.util.List;

/**
 * 杈撳叆涓�涓摼琛紝浠庡熬鍒板ご鎵撳嵃閾捐〃姣忎釜鑺傜偣鐨勫�笺��
 */
public class Reserveprint{
	public static void main(String[] args) {
		ListNode a=new ListNode(1);
		ListNode b=new ListNode(2);
		ListNode c=new ListNode(3);
		a.next=b;
		b.next=c;
		/*List<ListNode> list=new ArrayList<ListNode>();
		list.add(a);
		list.add(b);
		list.add(c);*/
		System.out.println(printListFromTailToHead(a));
		printListFromTailToHead(a);
	}
	/**
	 * [printListFromTailToHead description]
	 * @param  listNode 
	 * @return 杩斿洖閫嗗簭鐨勯摼琛�
	 */
	public static  ArrayList<Integer> printListFromTailToHead(ListNode listNode) {
			Stack<Integer> stack = new Stack<Integer>();
			ArrayList<Integer> list = new ArrayList<Integer>();
	       if (listNode!=null) {
	       		while(listNode!=null){
	       			stack.push(listNode.val);
	       			listNode=listNode.next;
	       		}
	       }
	       while (!stack.empty()){
	       		list.add(stack.pop());
	       }
	       return list;
	 }
}


class ListNode {

	int val;
	ListNode next=null;
	ListNode(int val){
		this.val=val;
	}
	public String toString(){
		return "the value: "+val;
	}
}